﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Boomerang.Common.Configuration;
using Boomerang.Management.UIHelpers;
using Boomerang.Management.UIForms;
using System.Threading;

namespace Boomerang.Management
{
    public partial class MainForm : Form
    {

        public MainForm()
        {
            InitializeComponent();

            //Load Current Configuration
            new ConfigurationListView(listView1);

        }

        #region Commands

        private void Save()
        {
            if (MessageBox.Show(this, "Previous Configuration will be ovewriten", "Confirm", MessageBoxButtons.OKCancel)
                != DialogResult.Cancel)
            {
                ConfigurationManager.Save();
            }
        }

        private void New()
        {
            OrganizationWizard orgForm = new OrganizationWizard();
            orgForm.Show();
        }

        private void Delete()
        {
            if (MessageBox.Show(this, "Are you sure you wan to delete ?", "Confirm", MessageBoxButtons.OKCancel)
                    != DialogResult.Cancel)
            {
                if (listView1.SelectedItems.Count <= 0) return;
                Organization org = listView1.SelectedItems[0].Tag as Organization;

                ConfigurationManager.RemoveOrganization(org);
            }
        }

        private void Edit()
        {
            if (listView1.SelectedItems.Count <= 0) return;
            Organization org = listView1.SelectedItems[0].Tag as Organization;

            OrganizationWizard orgForm = new OrganizationWizard(org);
            orgForm.Show();
        }

        #endregion

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            New();
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            New();
        }

        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            Edit();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Edit();
        }

        private void deleteToolStripButton_Click(object sender, EventArgs e)
        {
            Delete();
        }

        private void toolStripMenuItemDelete_Click(object sender, EventArgs e)
        {
            Delete();
        }


    }
}
